package com.woniu.humanresource.controller;

import com.woniu.humanresource.entity.CompensationScheme;
import com.woniu.humanresource.entity.CorporateBenefits;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.exception.GeneralException;
import com.woniu.humanresource.service.CorporateBenefitsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//企业福利
@RestController
public class CorporateBenefitisController {

    @Resource
    CorporateBenefitsService corporateBenefitsService;
    //分页查询企业福利
    @PostMapping("/corporatebenefits/{pageIndex}/{pageSize}")
    public ResponseText getCorporateBenefits(
                                                            @PathVariable("pageIndex") int pageIndex,
                                                             @PathVariable("pageSize") int pageSize,
                                                            @RequestBody CorporateBenefits corporateBenefits){
        ResponseText<PageBean<CorporateBenefits>> responseText=null;
        try {

            PageBean<CorporateBenefits> pageBean = corporateBenefitsService.selectCorporateBenefits(corporateBenefits, pageIndex, pageSize);
            responseText=new ResponseText<>(pageBean,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //添加企业福利
    @PostMapping("/addcorporatebenefits")
    public ResponseText addCorporateBenefits(@RequestBody CorporateBenefits corporateBenefits){
        ResponseText responseText=null;
        try {
            //待面试状态
            corporateBenefitsService.insertCorporateBenefits(corporateBenefits);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //删除企业福利
    @DeleteMapping("/deletecorporatebenefits/{id}")
    public ResponseText deleteCorporateBenefits(@PathVariable("id") int id){
        ResponseText responseText=null;
        try {
            corporateBenefitsService.deleteCorporateBenefits(id);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //修改企业福利
    @PutMapping("/updatecorporatebenefits")
    public ResponseText updateCorporateBenefits(@RequestBody CorporateBenefits corporateBenefits){
        ResponseText responseText=null;
        try {
            corporateBenefitsService.updateCorporateBenefits(corporateBenefits);
                    responseText=new ResponseText<PageBean<CorporateBenefits>>(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

}
